package com.dys.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.RedirectView;

/**
 * @className: com.dys.controller.ViewController
 * @description: SpringMVC_View视图
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/26 22:40
 */
@Controller
public class ViewController {

    /**
     * 通过view实现请求转发
     *
     * @return view对象
     */
    @RequestMapping("/getForwardView")
    public View getForwardView() {
        View view = null;
        view = new InternalResourceView("/forwardView.jsp");
        System.out.println("spring mvc view 请求转发......");
        return view;
    }

    /**
     * 通过view实现响应重定向
     *
     * @param request 请求对象
     * @return view
     */
    @RequestMapping("/getRedirectView")
    public View getRedirectView(HttpServletRequest request) {
        View view = null;
        view = new RedirectView(request.getContextPath() + "/redirectView.jsp");
        System.out.println("spring mvc view 响应重定向......");
        return view;
    }
}
